Skip to content

Fix regression fetching file:// URI scheme in fetch() and XMLHttpRequest requests on Android (#54626)#55706

Closed
bhamiltoncx wants to merge 4 commits intofacebook:mainfrom
terraware:issue-54626
Closed

Fix regression fetching file:// URI scheme in fetch() and XMLHttpRequest requests on Android (#54626)#55706
bhamiltoncx wants to merge 4 commits intofacebook:mainfrom
terraware:issue-54626

Conversation

@bhamiltoncx
Copy link
Contributor

Summary:

fetch() on file:// URIs is broken on RN Android, but works on RN iOS (#54626).

On Android, NetworkingModule powers the implementation of XMLHttpRequest, which is the implementation of fetch().

iOS's underlying implementation RCTNetworking uses RCTFileRequestHandler which correctly supports file:// URIs:

return [request.URL.scheme caseInsensitiveCompare:@"file"] == NSOrderedSame && !RCTIsBundleAssetURL(request.URL);

Android's equivalent BlobModule works correctly to handle file:// URIs, but NetworkingModule was changed in #52485 to construct a okhttp3.Response, passing in an okhttp3.Request using the file:// URI.

Unfortunately, okhttp3.Request.Builder.url() throws InvalidArgumentException whenever given non-HTTP/HTTPS URLs, which caused #54626.

The fix is pretty simple: clean up the behavior changed in #52485 to just pass in the data needed (status code, headers, and content length) rather than trying to wrap it in an okhttp3.Response.

Changelog:

[ANDROID] [FIXED] - file:// URIs passed to fetch() or XMLHttpRequest no longer fail (#54626)

Test Plan

Unit tests updated. Ran tests with:

  ./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest \
    --tests "com.facebook.react.modules.blob.BlobModuleTest" \
    --tests "com.facebook.react.modules.network.NetworkEventUtilTest" \
    --tests "com.facebook.react.modules.network.NetworkingModuleTest"

@meta-cla
Copy link

meta-cla bot commented Feb 23, 2026

Hi @bhamiltoncx!

Thank you for your pull request.

We require contributors to sign our Contributor License Agreement, and yours needs attention.

You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@bhamiltoncx bhamiltoncx changed the title Fix regression fetching file:// URI scheme in fetch() and XMLHttpRequest requests (#54626) Fix regression fetching file:// URI scheme in fetch() and XMLHttpRequest requests on Android (#54626) Feb 23, 2026
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 23, 2026
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Feb 23, 2026
…est requests (facebook#54626)

On Android, `NetworkingModule` powers the implementation of
`XMLHttpRequest`, which is the implementation of `fetch()`.

iOS's underlying implementation `RCTNetworking` uses
`RCTFileRequestHandler` which correctly supports `file://` URIs:

https://github.com/facebook/react-native/blob/56e1710b73f0011516872bc6a62e52626588839c/packages/react-native/Libraries/Network/RCTFileRequestHandler.mm#L44

Android's equivalent `BlobModule` works correctly to handle `file://`
URIs, but `NetworkingModule` was changed in facebook#52485 to construct a
`okhttp3.Response`, passing in an `okhttp3.Request` using the
`file://` URI.

Unfortunately, `okhttp3.Request.Builder.url()` throws
`InvalidArgumentException` whenever given non-HTTP/HTTPS URLs, which
caused facebook#54626.

The fix is pretty simple: clean up the behavior changed in facebook#52485 to
just pass in the data needed (status code, headers, and content
length) rather than trying to wrap it in an `okhttp3.Response`.

Tested:
  ./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest \
    --tests "com.facebook.react.modules.blob.BlobModuleTest" \
    --tests "com.facebook.react.modules.network.NetworkEventUtilTest" \
    --tests "com.facebook.react.modules.network.NetworkingModuleTest"
@bhamiltoncx
Copy link
Contributor Author

@huntie , apologies for the direct ping, but I haven't been at Meta in ages and I don't know how the GitHub -> Phabricator pipeline works these days. :)

Any thoughts on this PR? It fixes a gnarly regression from #52485 .

Copy link
Member

@huntie huntie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome, thanks. Will import and test.

@meta-codesync
Copy link

meta-codesync bot commented Feb 25, 2026

@huntie has imported this pull request. If you are a Meta employee, you can view this in D94377526.

huntie added a commit to huntie/react-native that referenced this pull request Feb 26, 2026
Summary:
Follows facebook#55706.

Updates the signature of `onCreateRequest`, and removes legacy `onCreateRequest` and `onResponseReceived` overloads — effectively de-OkHttp-ing this internal API.

Changelog: [Internal]

Differential Revision: D94510863
@meta-codesync meta-codesync bot closed this in e76a6e2 Feb 26, 2026
@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @bhamiltoncx in e76a6e2

When will my fix make it into a release? | How to file a pick request?

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Feb 26, 2026
@react-native-bot react-native-bot added the Merged This PR has been merged. label Feb 26, 2026
@meta-codesync
Copy link

meta-codesync bot commented Feb 26, 2026

@huntie merged this pull request in e76a6e2.

@bhamiltoncx
Copy link
Contributor Author

Wonderful! Thanks for shepherding this fix along. I know it'll help a bunch of Android users.

huntie added a commit to huntie/react-native that referenced this pull request Feb 26, 2026
Summary:

Follows facebook#55706.

Updates the signature of `onCreateRequest`, and removes legacy `onCreateRequest` and `onResponseReceived` overloads — effectively de-OkHttp-ing this internal API.

Changelog: [Internal]

Differential Revision: D94510863
huntie added a commit to huntie/react-native that referenced this pull request Feb 26, 2026
Summary:

Follows facebook#55706.

Updates the signature of `onCreateRequest`, and removes legacy `onCreateRequest` and `onResponseReceived` overloads — effectively de-OkHttp-ing this internal API.

Changelog: [Internal]

Differential Revision: D94510863
huntie added a commit to huntie/react-native that referenced this pull request Feb 26, 2026
Summary:
Follows facebook#55706.

Updates the signature of `onCreateRequest`, and removes legacy `onCreateRequest` and `onResponseReceived` overloads — effectively de-OkHttp-ing this internal API.

Changelog: [Internal]

Differential Revision: D94510863
meta-codesync bot pushed a commit that referenced this pull request Feb 27, 2026
Summary:
Pull Request resolved: #55769

Follows #55706.

Updates the signature of `onCreateRequest`, and removes legacy `onCreateRequest` and `onResponseReceived` overloads — effectively de-OkHttp-ing this internal API.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D94510863

fbshipit-source-id: ce438af6e1cd352ce7afff5588621612e03f5cf9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants